package com.anysoft.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by lty on 2017/11/8.
 */

public class MyViewPager extends ViewPager {
    public MyViewPager(Context context) {
        super(context);
    }

    public MyViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
//        getParent().requestDisallowInterceptTouchEvent(true);
        return super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        return super.dispatchTouchEvent(ev);
    }

    private float xDistance, yDistance, xLast, yLast;

    @Override
    public boolean onTouchEvent(MotionEvent ev) {

//        switch (ev.getAction()) {
//            case MotionEvent.ACTION_DOWN:
//                xDistance = yDistance = 0f;
//                xLast = ev.getX();
//                yLast = ev.getY();
//                getParent().requestDisallowInterceptTouchEvent(true);
//                break;
//            case MotionEvent.ACTION_MOVE:
//                float currentX = ev.getX();
//                float currentY = ev.getY();
//                //差值
//                xDistance += Math.abs(currentX - xLast);
//                yDistance += Math.abs(currentY - yLast);
//                xLast = currentX;
//                yLast = currentY;
//                if(xDistance <= yDistance)
//                    return super.onTouchEvent(ev);  // 消耗
//                else
//                    return false;                   // 往下传递
//            case MotionEvent.ACTION_UP:
//
//                break;
//        }
        return super.onTouchEvent(ev);
    }
}
